import type { Router } from 'vue-router'
import { setRouteEmitter } from '@/utils/route-listener'
import setupUserLoginInfoGuard from './userLoginInfo'
import setupPermissionGuard from './permission'

function setupPageGuard(router: Router) {
	router.beforeEach(async (to) => {
		// emit route change
		setRouteEmitter(to)
	})
}

export default function createRouteGuard(router: Router) {
	// 设置路由守卫
	setupPageGuard(router)
	// 处理页面加载时的动画
	setupUserLoginInfoGuard(router)
	// 设置权限相关的守卫逻辑
	setupPermissionGuard(router)
}
